﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.Supervise.Web.Meet
{
    public partial class MeetAdd : BasePage
    {
        IBLL.IBLL_ProcureCatalog ihc = new HZ.Supervise.BLL.BLL_ProcureCatalog();
        IBLL.IBLL_User log = BLLFactory.BLL_User(); 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["mid"] != null)
                {
                    setBind();
                }
            }
        }

        void setBind()
        {
            string str = string.Format(" and MeetID='{0}'", Request["mid"].ToString());
            DataTable dt = ihc.GetMeetList2(str);
            if (dt.Rows.Count == 1)
            {
                btnAdd.Text = "保 存";
                txtMeetName.Text = dt.Rows[0]["MeetName"].ToString();
                txtMeetPlace.Text = dt.Rows[0]["MeetPlace"].ToString();
                txtBaoMingEndTime.Text = Convert.ToDateTime(dt.Rows[0]["BaoMingEndTime"]).ToString("yyyy-MM-dd HH:mm");
                txtStartTime.Text = Convert.ToDateTime(dt.Rows[0]["MeetStartTime"]).ToString("yyyy-MM-dd HH:mm");
                txtEndTime.Text = Convert.ToDateTime(dt.Rows[0]["MeetEndTime"]).ToString("yyyy-MM-dd HH:mm");
                txtContent.Text = dt.Rows[0]["MeetContent"].ToString();
            }
            else
            {
                btnAdd.Visible = false;
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMeetName.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("会议名称不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(txtBaoMingEndTime.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("报名截止时间不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(txtStartTime.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("起始时间不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(txtEndTime.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("截止时间不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(txtContent.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("培训会议内容不能为空！");
                return;
            }
            if (Convert.ToDateTime(txtBaoMingEndTime.Text.Trim()) > Convert.ToDateTime(txtStartTime.Text.Trim()) || Convert.ToDateTime(txtBaoMingEndTime.Text.Trim()) > Convert.ToDateTime(txtEndTime.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("报名时间应小于会议开始或结束时间！");
                return;
            }
            if (Convert.ToDateTime(txtStartTime.Text.Trim()) > Convert.ToDateTime(txtEndTime.Text.Trim()))
            {
                HZ.Web.WebUtil.Alert("会议开始时间应小于结束时间！");
                return;
            }
            Model.Meet mt = new Model.Meet();
            if (Request["mid"] != null)
            {
                mt.MeetID = Request["mid"].ToString();
            }
            mt.MeetName = txtMeetName.Text.Trim();
            mt.MeetContent = txtContent.Text.Trim();
            mt.MeetPlace = txtMeetPlace.Text.Trim();
            mt.BaoMingEndTime = Convert.ToDateTime(txtBaoMingEndTime.Text.Trim());
            mt.MeetStartTime = Convert.ToDateTime(txtStartTime.Text.Trim());
            mt.MeetEndTime = Convert.ToDateTime(txtEndTime.Text.Trim());
            if (ihc.AddMeet(mt) == 1)
            {
                HZ.Supervise.Model.KeyOperationLogJG keyOperationLog = new HZ.Supervise.Model.KeyOperationLogJG();
                keyOperationLog.OperationLogSerialID = Guid.NewGuid().ToString();
                keyOperationLog.Operator = CurrentAccount.GetUser().UserID;
                keyOperationLog.OrgID = CurrentAccount.GetUser().Org.OrgID;
                keyOperationLog.OperateTime = DateTime.Now;
                keyOperationLog.OperateMessage = string.Format("[{1}]会议信息[{0}]", mt.MeetID, Request["mid"] != null ? "修改" : "新增");
                log.AddKeyOperationLog(keyOperationLog);
            }
            else
            {
                HZ.Web.WebUtil.Alert("操作失败！");
            }
            Response.Redirect("MeetList_zx.aspx");
        }
    }
}